home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / util / rexx / filofaxa.lha / FiloFaxASCII.dfa next >
Text File  |  1995-10-26  |  11KB  |  612 lines

  1. /* $Revision Header built automatically *************** (do not edit) ************
  2. **
  3. ** ⌐ Copyright by Dirk Federlein
  4. **
  5. ** File             : FiloFaxTeX.dfa
  6. ** Created on       : Dienstag, 25.10.94 21:40:03
  7. ** Created by       : Dirk Federlein
  8. ** Current revision : V1.0
  9. **
  10. **
  11. ** Purpose
  12. ** -------
  13. **     Outputs one or more ASCII files, each containing 4 DinA6 pages
  14. **     with formatted addresses.
  15. **
  16. **     Adresses with another starting letter with the predecessors get a new
  17. **     page.
  18. **
  19. **     The pages may be copied to the printer (prt:/par:) using the usual copy
  20. **     command.
  21. **
  22. **     Each A4-page contains 96x84 chars.
  23. **
  24. **     This script needs DFA v2.5 and above to run properly.
  25. **
  26. *********************************************************************************/
  27.  
  28. tabchar = '09'X
  29. cr  = '0A'X
  30.  
  31. outbody     = 'RAM:DFASheet_'
  32. outext      = '.txt'
  33.  
  34. options results
  35.  
  36. if ~show(ports, DFA) then
  37.     exit 10
  38.  
  39. address "DFA"
  40.  
  41. /* Init "page" 1 */
  42.  
  43. page1.  = ""
  44.  
  45. /* Init page #2 */
  46.  
  47. page2.  = ""
  48.  
  49. /* Init page #3 */
  50.  
  51. page3.  = ""
  52.  
  53. /* Init page #4 */
  54.  
  55. page4.  = ""
  56.  
  57. /* Clear address buffer */
  58.  
  59. tmpadr.0 = "" /* First Name / Name */
  60. tmpadr.1 = "" /* Street */
  61. tmpadr.2 = "" /* ZIP City */
  62. tmpadr.3 = "" /* Phone */
  63. tmpadr.4 = "" /* Fax. - if available */
  64. tmpadr.5 = "" /* Comment - if available */
  65.  
  66. pageitems = 0
  67. pagelines = 0
  68. pagenum = 1
  69. currentline = 0
  70.  
  71. maxpagelines = 40   /* Max. lines per (A6) page */
  72. leftoffset = 8      /* left offset */
  73. maxlinelen = 46     /* Max. chars per (A6) line */
  74. pageskip = 5        /* Skip between the upper and the lower 2 A6 pages */
  75.  
  76. skipnext = 0
  77.  
  78. sheetnum = 1
  79. outname = outbody||sheetnum||outext
  80.  
  81. gui input off output off
  82.  
  83. FIRST STEM ADR.
  84.  
  85. CurrentLetter   = left(ADR.ADDRESS.2,1)
  86. LastLetter      = left(ADR.ADDRESS.2,1)
  87.  
  88. do while RC = 0
  89.  
  90.         /* Init all strings... */
  91.  
  92.     tmpadr. = ""
  93.     ready = 0
  94.     adritem = 0
  95.     fmtline = 0
  96.  
  97.     do while ready = 0
  98.  
  99.             /* <FIRST NAME> */
  100.  
  101.         if adritem = 1 then
  102.         do
  103.             if ADR.ADDRESS.adritem ~= "" then
  104.                 tmpadr.fmtline = ADR.ADDRESS.adritem
  105.         end
  106.  
  107.             /* <SURNAME> */
  108.  
  109.         if adritem = 2 then
  110.         do
  111.             if ADR.ADDRESS.adritem ~= "" then
  112.             do
  113.                 if tmpadr.fmtline ~= "" then
  114.                     tmpadr.fmtline = tmpadr.fmtline ADR.ADDRESS.adritem
  115.                 else
  116.                     tmpadr.fmtline = ADR.ADDRESS.adritem
  117.             end
  118.  
  119.             if tmpadr.fmtline ~= "" then
  120.                 fmtline = fmtline+1
  121.  
  122.         end
  123.  
  124.             /* <STREET> */
  125.  
  126.         if adritem = 4 then
  127.         do
  128.             if ADR.ADDRESS.adritem ~= "" then
  129.             do
  130.                 tmpadr.fmtline = ADR.ADDRESS.adritem
  131.  
  132.                 fmtline = fmtline+1
  133.             end
  134.         end
  135.  
  136.             /* <ZIP> */
  137.  
  138.         if adritem = 5 then
  139.         do
  140.             if ADR.ADDRESS.adritem ~= "" then
  141.                 tmpadr.fmtline = ADR.ADDRESS.adritem
  142.  
  143.         end
  144.  
  145.             /* <CITY> */
  146.  
  147.         if adritem = 6 then
  148.         do
  149.             if ADR.ADDRESS.adritem ~= "" then
  150.             do
  151.                 if tmpadr.fmtline ~= "" then
  152.                     tmpadr.fmtline = tmpadr.fmtline ADR.ADDRESS.adritem
  153.                 else
  154.                     tmpadr.fmtline = ADR.ADDRESS.adritem
  155.             end
  156.  
  157.             if tmpadr.fmtline ~= "" then
  158.                 fmtline = fmtline+1
  159.  
  160.         end
  161.  
  162.             /* <COUNTRY> */
  163.  
  164.         if adritem = 8 then
  165.         do
  166.             if ADR.ADDRESS.adritem ~= "" then
  167.             do
  168.                 if (index(UPPER(ADR.ADDRESS.adritem), "GERMANY") == 0) & (index(UPPER(ADR.ADDRESS.adritem), "DEUTSCHLAND") == 0) then
  169.                 do
  170.                     tmpadr.fmtline = ADR.ADDRESS.adritem
  171.  
  172.                     fmtline = fmtline+1
  173.                 end
  174.             end
  175.         end
  176.  
  177.             /* <PHONE> */
  178.  
  179.         if adritem = 10 then
  180.         do
  181.             if ADR.ADDRESS.adritem ~= "" then
  182.             do
  183.                 if index(ADR.ADDRESS.adritem, "|") = 0 then
  184.                 do
  185.                     tmpadr.fmtline = "Tel." ADR.ADDRESS.adritem
  186.  
  187.                     fmtline = fmtline+1
  188.                 end
  189.                 else
  190.                 do
  191.                     phonecnt = 0
  192.  
  193.                     /* START...'|' */
  194.  
  195.                     phonecnt = index(ADR.ADDRESS.adritem, "|")
  196.                     tmpadr.fmtline = "Tel." left(ADR.ADDRESS.adritem,phonecnt-1)
  197.                     fmtline = fmtline+1
  198.  
  199.                     phonecnt = phonecnt + 1
  200.  
  201.                     nextcnt = 0
  202.                     do while index(ADR.ADDRESS.adritem, "|", phonecnt) ~= 0
  203.                         nextcnt = index(ADR.ADDRESS.adritem, "|", phonecnt)
  204.                         tmpadr.fmtline = "    " substr(ADR.ADDRESS.adritem, phonecnt, nextcnt-phonecnt)
  205.                         fmtline = fmtline+1
  206.                         phonecnt = nextcnt+1
  207.                     end
  208.  
  209.                     /* '|'...END */
  210.  
  211.                     tmpadr.fmtline = "    " right(ADR.ADDRESS.adritem, LENGTH(ADR.ADDRESS.adritem)-phonecnt+1)
  212.                     fmtline = fmtline+1
  213.                 end
  214.             end
  215.         end
  216.  
  217.             /* <FAX> */
  218.  
  219.         if adritem = 11 then
  220.         do
  221.             if ADR.ADDRESS.adritem ~= "" then
  222.             do
  223.                 if index(ADR.ADDRESS.adritem, "|") = 0 then
  224.                 do
  225.                     tmpadr.fmtline = "Fax." ADR.ADDRESS.adritem
  226.  
  227.                     fmtline = fmtline+1
  228.                 end
  229.                 else
  230.                 do
  231.                     phonecnt = 0
  232.  
  233.                     /* START...'|' */
  234.  
  235.                     phonecnt = index(ADR.ADDRESS.adritem, "|")
  236.                     tmpadr.fmtline = "Fax." left(ADR.ADDRESS.adritem,phonecnt-1)
  237.                     fmtline = fmtline+1
  238.  
  239.                     phonecnt = phonecnt + 1
  240.  
  241.                     nextcnt = 0
  242.                     do while index(ADR.ADDRESS.adritem, "|", phonecnt) ~= 0
  243.                         nextcnt = index(ADR.ADDRESS.adritem, "|", phonecnt)
  244.                         tmpadr.fmtline = "    " substr(ADR.ADDRESS.adritem, phonecnt, nextcnt-phonecnt)
  245.                         fmtline = fmtline+1
  246.                         phonecnt = nextcnt+1
  247.                     end
  248.  
  249.                     /* '|'...END */
  250.  
  251.                     tmpadr.fmtline = "    " right(ADR.ADDRESS.adritem, LENGTH(ADR.ADDRESS.adritem)-phonecnt+1)
  252.                     fmtline = fmtline+1
  253.                 end
  254.             end
  255.         end
  256.  
  257.             /* <COMMENT> */
  258.  
  259.         if adritem = 15 then
  260.         do
  261.             if ADR.ADDRESS.adritem ~= "" then
  262.             do
  263.                 tmpadr.fmtline = ADR.ADDRESS.adritem
  264.  
  265.                 fmtline = fmtline+1
  266.             end
  267.         end
  268.  
  269.             /* Process next address item... */
  270.  
  271.         adritem = adritem+1
  272.  
  273.  
  274.             /* Last item reached ? */
  275.  
  276.         if adritem>15 then
  277.             ready = 1
  278.     end
  279.  
  280.     addresslines = fmtline+1  /* fmtline count starts with zero */
  281.  
  282.     if CurrentLetter ~= LastLetter then
  283.     do
  284.         /* Fill empty lines of page 1 and page 3 */
  285.  
  286.         if pagenum = 1 then
  287.         do
  288.             i = currentline
  289.  
  290.             do while i < maxpagelines
  291.                 page1.i = INSERT(" ", page1.i, leftoffset, maxlinelen, " ")
  292.                 i = i+1
  293.             end
  294.         end
  295.  
  296.         if pagenum = 3 then
  297.         do
  298.             i = currentline
  299.  
  300.             do while i < maxpagelines
  301.                 page3.i = INSERT(" ", page3.i, leftoffset, maxlinelen, " ")
  302.                 i = i+1
  303.             end
  304.         end
  305.  
  306.         pagenum = pagenum + 1
  307.  
  308.         if pagenum > 4 then
  309.         do
  310.             /* Output all 4 pages... */
  311.  
  312.             if open('outfile', outname, 'W') = 0 then
  313.             do
  314.                 gui input on output on
  315.  
  316.                 exit 10
  317.             end
  318.             else
  319.             do
  320.  
  321.                 i = 0
  322.  
  323.                 do while i < maxpagelines
  324.  
  325.                     numchars = writech('outfile', page1.i page2.i (cr))
  326.                     i = i+1
  327.  
  328.                 end
  329.  
  330.                 i = 0
  331.  
  332.                 do while i < pageskip
  333.  
  334.                     numchars = writech('outfile', (cr))
  335.                     i = i+1
  336.  
  337.                 end
  338.  
  339.                 i = 0
  340.  
  341.                 do while i < maxpagelines
  342.  
  343.                     numchars = writech('outfile', page3.i page4.i (cr))
  344.                     i = i+1
  345.  
  346.                 end
  347.  
  348.                 call close 'outfile'
  349.  
  350.                 sheetnum = sheetnum + 1
  351.                 outname = outbody||sheetnum||outext
  352.             end
  353.  
  354.             currentline = 0
  355.             pagenum = 1
  356.             page1. = ""
  357.             page2. = ""
  358.             page3. = ""
  359.             page4. = ""
  360.  
  361.         end
  362.         pageitems = 0
  363.         currentline = 0
  364.  
  365.     end
  366.  
  367.     pageitems = pageitems + 1
  368.  
  369.     if pagenum = 1 then
  370.     do
  371.         if (currentline + addresslines - 1) < maxpagelines then
  372.         do
  373.             linecnt = 0
  374.  
  375.             do while linecnt <= fmtline
  376.                 if tmpadr.linecnt ~= "" then
  377.                 do
  378.                     page1.currentline = INSERT(tmpadr.linecnt, page1.currentline, leftoffset, maxlinelen, " ")
  379.                     currentline = currentline + 1
  380.                 end
  381.  
  382.                 linecnt = linecnt + 1
  383.             end
  384.  
  385.             page1.currentline = INSERT(" ", page1.currentline, leftoffset, maxlinelen, " ")
  386.             currentline = currentline +1
  387.  
  388.         end
  389.         else
  390.         do
  391.             currentline = 0
  392.             pageitems = 0
  393.             pagenum = 2
  394.         end
  395.  
  396.  
  397.     end
  398.  
  399.     if pagenum = 2 then
  400.     do
  401.         if (currentline + addresslines - 1) < maxpagelines then
  402.         do
  403.             linecnt = 0
  404.  
  405.             do while linecnt <= fmtline
  406.                 if tmpadr.linecnt ~= "" then
  407.                 do
  408.                     page2.currentline = INSERT(tmpadr.linecnt, page2.currentline, leftoffset, maxlinelen, " ")
  409.                     currentline = currentline + 1
  410.                 end
  411.  
  412.                 linecnt = linecnt + 1
  413.             end
  414.  
  415.             page2.currentline = INSERT(" ", page2.currentline, leftoffset, maxlinelen, " ")
  416.             currentline = currentline +1
  417.  
  418.         end
  419.         else
  420.         do
  421.             pagenum = 3
  422.             pageitems = 0
  423.             currentline = 0
  424.         end
  425.     end
  426.  
  427.     if pagenum = 3 then
  428.     do
  429.         if (currentline + addresslines - 1) < maxpagelines then
  430.         do
  431.             linecnt = 0
  432.  
  433.             do while linecnt <= fmtline
  434.                 if tmpadr.linecnt ~= "" then
  435.                 do
  436.                     page3.currentline = INSERT(tmpadr.linecnt, page3.currentline, leftoffset, maxlinelen, " ")
  437.                     currentline = currentline + 1
  438.                 end
  439.  
  440.                 linecnt = linecnt + 1
  441.             end
  442.  
  443.             page3.currentline = INSERT(" ", page3.currentline, leftoffset, maxlinelen, " ")
  444.             currentline = currentline +1
  445.  
  446.         end
  447.         else
  448.         do
  449.             pagenum = 4
  450.             pageitems = 0
  451.             currentline = 0
  452.         end
  453.     end
  454.  
  455.     if pagenum = 4 then
  456.     do
  457.         if (currentline + addresslines - 1) < maxpagelines then
  458.         do
  459.             linecnt = 0
  460.  
  461.             do while linecnt <= fmtline
  462.                 if tmpadr.linecnt ~= "" then
  463.                 do
  464.                     page4.currentline = INSERT(tmpadr.linecnt, page4.currentline, leftoffset, maxlinelen, " ")
  465.                     currentline = currentline + 1
  466.                 end
  467.  
  468.                 linecnt = linecnt + 1
  469.             end
  470.  
  471.             page4.currentline = INSERT(" ", page4.currentline, leftoffset, maxlinelen, " ")
  472.             currentline = currentline +1
  473.  
  474.         end
  475.         else
  476.         do
  477.             /* Output this page to file...*/
  478.  
  479.             if open('outfile', outname, 'W') = 0 then
  480.             do
  481.                 gui input on output on
  482.  
  483.                 exit 10
  484.             end
  485.             else
  486.             do
  487.                 i = 0
  488.  
  489.                 do while i < maxpagelines
  490.  
  491.                     numchars = writech('outfile', page1.i page2.i (cr))
  492.                     i = i+1
  493.  
  494.                 end
  495.  
  496.                 i = 0
  497.  
  498.                 do while i < pageskip
  499.  
  500.                     numchars = writech('outfile', (cr))
  501.                     i=i+1
  502.  
  503.                 end
  504.  
  505.                 i = 0
  506.  
  507.                 do while i < maxpagelines
  508.  
  509.                     numchars = writech('outfile', page3.i page4.i (cr))
  510.                     i = i+1
  511.  
  512.                 end
  513.  
  514.                 call close 'outfile'
  515.                 sheetnum = sheetnum + 1
  516.                 outname = outbody||sheetnum||outext
  517.             end
  518.  
  519.             currentline = 0
  520.             pageitems = 0
  521.             pagenum = 1
  522.             skipnext = 1
  523.             page1. = ""
  524.             page2. = ""
  525.             page3. = ""
  526.             page4. = ""
  527.  
  528.         end
  529.     end
  530.  
  531.     if skipnext = 0 then
  532.     do
  533.         next stem adr.
  534.  
  535.         LastLetter      = CurrentLetter
  536.         CurrentLetter   = left(ADR.ADDRESS.2,1)
  537.     end
  538.     else
  539.         skipnext = 0
  540. end
  541.  
  542. if (pageitems > 0) | (pagenum > 1) then
  543. do
  544.  
  545.     /* Output all 4 pages... */
  546.  
  547.     if open('outfile', outname, 'W') = 0 then
  548.     do
  549.         gui input on output on
  550.  
  551.         exit 10
  552.     end
  553.     else
  554.     do
  555.  
  556.         /* Fill empty lines of page 1 and page 3 */
  557.  
  558.         i = currentline
  559.  
  560.         if pagenum = 1 then
  561.         do
  562.             do while i < maxpagelines
  563.                 page1.i = INSERT(" ", page1.i, leftoffset, maxlinelen, " ")
  564.                 i = i+1
  565.             end
  566.         end
  567.  
  568.         if pagenum = 3 then
  569.         do
  570.             do while i < maxpagelines
  571.                 page3.i = INSERT(" ", page3.i, leftoffset, maxlinelen, " ")
  572.                 i = i+1
  573.             end
  574.         end
  575.  
  576.  
  577.         i = 0
  578.  
  579.         do while i < maxpagelines
  580.  
  581.             numchars = writech('outfile', page1.i page2.i (cr))
  582.             i = i+1
  583.  
  584.         end
  585.  
  586.         i = 0
  587.  
  588.         do while i < pageskip
  589.  
  590.             numchars = writech('outfile', (cr))
  591.             i=i+1
  592.  
  593.         end
  594.  
  595.         i = 0
  596.  
  597.         do while i < maxpagelines
  598.  
  599.             numchars = writech('outfile', page3.i page4.i (cr))
  600.             i = i+1
  601.  
  602.         end
  603.  
  604.         call close 'outfile'
  605.    end
  606. end
  607.  
  608. gui input on output on
  609.  
  610. exit
  611.  
  612.